package com.ck.common.bean;

import com.ck.common.constant.Constants;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class McApiResp<T> {

    String code;
    String desc;
    T retData;

    public McApiResp(String code, String desc, T retData) {
        this.code = code;
        this.desc = desc;
        this.retData = (T) retData;
    }

    /**
     * 返回失败
     *
     * @param rstMsg
     */
    public McApiResp(String rstMsg) {
        this.code = Constants.FAIL;
        this.desc = rstMsg;
        this.retData = (T) "";
    }

    /**
     * 返回成功
     *
     * @param rstObj
     */
    public McApiResp(T rstObj) {
        this.code = Constants.SUCCESS;
        this.desc = "操作成功";
        this.retData = rstObj;
    }

    /**
     * 初始化失败结果
     *
     * @param msg
     * @return
     */
    public static McApiResp fail(String msg) {
        return new McApiResp(msg);
    }

    /**
     * 初始化成功结果
     *
     * @return
     */
    public static McApiResp<Object> success(Object obj) {
        return new McApiResp<>(Constants.SUCCESS, "Success", obj);
    }
}
